package pyip.lib.javalearn.aop.dynamicproxy.spring.autoadvice;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import pyip.lib.javalearn.aop.dynamicproxy.Greeting;

public class Client {

    public static void main(String[] args) {
        declarationPattern();
        // programPattern();
    }

    private static void declarationPattern() {
        ApplicationContext context = new ClassPathXmlApplicationContext("pyip/lib/javalearn/aop/dynamicproxy/spring/autoadvice/aop-autoadvice.xml");
        // 注意：转型为接口
        Greeting greeting = (Greeting) context.getBean("greetingAutoAdviceImpl");
        greeting.sayHello("Jack");

        // 注意：转型为目标类，而并非它的 Greeting 接口
        GreetingAutoAdviceImpl greetingAutoAdviceImpl = (GreetingAutoAdviceImpl) context.getBean("greetingAutoAdviceImpl");
        greetingAutoAdviceImpl.sayHello("Jack");
        greetingAutoAdviceImpl.goodMorning("Jack");
        greetingAutoAdviceImpl.goodNight("Jack");

        ((ClassPathXmlApplicationContext) context).close();
    }

    private static void programPattern() {
    }
}